﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;

namespace cs_utilities.network
{
    public class network
    {
        private network() { }

        //---------------------------------------------------------------------------
        public static bool can_connect_port(string addr, int port, out int err_code)
        {
            bool res = false;
            err_code = 0;

            try
            {
                Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                s.Connect(addr, port);
                res = s.Connected;

                s.Close();
            }
            catch (SocketException e)
            {
                err_code = e.ErrorCode;
                res = false;
            }

            return res;
        }
        //---------------------------------------------------------------------------
    }
}